package md.sv.dbu.sender;

import md.sv.dbu.mq.MQSender;

/**
 * @author MG
 */
public class MQMessageSender implements MessageSender {

    private MQSender mqSender;
    private boolean byteMessage;

    @Override
    public boolean connect(String managerName, String queueName, boolean byteMessage) {
        this.byteMessage = byteMessage;

        mqSender = new MQSender(managerName, queueName);
        if (mqSender.connect()) {
            return true;
        } else {
            close();
            return false;
        }
    }

    @Override
    public void close() {
        if (mqSender != null) {
            mqSender.close();
            mqSender = null;
        }
    }

    @Override
    public void sendMessage(String message) {
        if (mqSender != null) {
            mqSender.send(message, byteMessage);
        }
    }
}
